package root.electronclass.electronclass.school

import androidx.recyclerview.widget.GridLayoutManager
import root.electronclass.electronclass.common.base.BasicAdapter
import root.electronclass.electronclass.common.base.ViewBindingActivity
import root.electronclass.electronclass.databinding.ActivitySchoolStyleBinding
import root.electronclass.electronclass.databinding.ItemItemSchoolStyleBinding
import root.electronclass.electronclass.other.PictureActivity
import root.electronclass.electronclass.setup
import root.electronclass.electronclass.mvp.GlobalParameter
import root.electronclass.electronclass.mvp.entity.OrgSchoolInfoVO
import root.electronclass.electronclass.mvp.entity.SchoolPicDto

class SchoolStyleActivity : ViewBindingActivity<ActivitySchoolStyleBinding>() {
    private var picList = arrayListOf<String>()
    private val schoolInfoVO: OrgSchoolInfoVO = GlobalParameter.getSchoolInfo()
    override fun init() {
        binding.top.setup(lifecycle, "校园风采")
        binding.back.back.setOnClickListener {
            finish()
        }
        binding.recycler.layoutManager = GridLayoutManager(this, 4)
        binding.recycler.adapter = adapter
        if (schoolInfoVO.picJson.size != null && schoolInfoVO.picJsonFormat.size > 0) {
            adapter.refresh(schoolInfoVO.picJsonFormat)
            for (pic in schoolInfoVO.picJsonFormat) {
                picList.add(pic.url)
            }
        }
    }

    private val adapter = BasicAdapter<SchoolPicDto, ItemItemSchoolStyleBinding> { holder, item ->
        holder.binding.iv.setImageURI(item?.url)
        holder.binding.iv.setOnClickListener {
            PictureActivity.startActivity(this@SchoolStyleActivity, picList, holder.adapterPosition)
        }
    }


}